#ifdef KITSCHY_DEBUG_MEMORY 
#include "debug_memorymanager.h"
#endif

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"

#include "BList.h"
#include "BVector.h"
#include "geometrics.h"
#include "quaternion.h"
#include "symbol.h"
#include "sort.h"
#include "ontology.h"
#include "featureterm.h"
#include "FTKBase.h"

#include "AWLocalViewport.h"

#include "AWEntity.h"
#include "AWMessage.h"
#include "AWScenario.h"
#include "AWBody.h"
#include "AWSensor.h"
#include "AWSelfSensor.h"
#include "AWBrain.h"
#include "AWAgent.h"
#include "AWWorld.h"


AW_SelfSensor::AW_SelfSensor(Ontology *O,FTKBase *M) : AW_Sensor(O,M) 
{
	class_name->set("AW_SelfSensor");

	m_ontology->new_sort("sensed-agent","any",7,"name","symbol","x","float","y","float","z","float",
															    "dirx","float","diry","float","dirz","float");
	m_ontology->new_sort("sensed-self","sensed-agent",0);


} /* AW_SelfSensor */ 


AW_SelfSensor::AW_SelfSensor(FILE *fp,Ontology *O,FTKBase *M) : AW_Sensor(O,M)
{
	class_name->set("AW_SelfSensor");
	load(fp);

	m_ontology->new_sort("sensed-agent","any",7,"name","symbol","x","float","y","float","z","float",
															    "dirx","float","diry","float","dirz","float");
	m_ontology->new_sort("sensed-self","sensed-agent",0);

} /* AW_SelfSensor */ 


AW_SelfSensor::~AW_SelfSensor() 
{
} /* AW_SelfSensor::~AW_SelfSensor */ 


List<FeatureTerm> *AW_SelfSensor::sense(AW_Agent *a,AW_World *w)
{
	List<FeatureTerm> *l1;
	char tmp[256];

	l1=new List<FeatureTerm>;
	sprintf(tmp,"(define (sensed-self) (name \"%s\") (x %f) (y %f) (z %f) "
													"(dirx %f) (diry %f) (dirz %f))",
													a->get_AgentName()->get(),
													a->get_pos().x,a->get_pos().y,a->get_pos().z,
													a->get_dir().x,a->get_dir().y,a->get_dir().z);
	{
		FeatureTerm *ft=FeatureTerm::fromStringNOOS(tmp,m_memory,m_ontology);
		l1->Add(ft);
	}

	return l1;
} /* AW_SelfSensor::Sense */ 


bool AW_SelfSensor::is_a(char *c)
{
	if (strcmp(c,"AW_SelfSensor")==0) return true;

	return AW_Sensor::is_a(c);
} /* AW_SelfSensor::is_a */ 


bool AW_SelfSensor::is_a(Symbol *c)
{
	if (c->cmp("AW_SelfSensor")) return true;

	return AW_Sensor::is_a(c);
} /* AW_SelfSensor::is_a */ 
